package com.wpzf.zxhc.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.wpzf.common.core.utils.ServletUtils;
import com.wpzf.common.core.web.domain.AjaxResult;
import com.wpzf.common.log.annotation.Log;
import com.wpzf.common.log.enums.BusinessType;
import com.wpzf.common.security.service.TokenService;
import com.wpzf.ndhc.service.WpzfNdhcXjtbTbBaseService;
import com.wpzf.system.api.model.LoginUser;
import com.wpzf.zxhc.utils.ExcelUtils;
import com.wpzf.zxhc.domain.*;
import com.wpzf.zxhc.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    CommonService commonService;

    @Autowired
    WpzfTbhcjgService wpzfTbhcjgService;

    @Autowired
    WpzfUnitHcTaskService wpzfUnitHcTaskService;

    @Autowired
    WpzfJlHcTaskService wpzfJlHcTaskService;

    @Autowired
    WpzfShTbService wpzfShTbService;

    @Autowired
    WpzfZgTbTaskService wpzfZgTbTaskServiceImpl;

    @Autowired
    WpzfNdhcXjtbTbBaseService wpzfNdhcXjtbTbBaseService;


    @Autowired
    TokenService tokenService;

    @Autowired
    XjtbTbBaseService xjtbTbBaseService;

    /*保存核查结果*/
    @Transactional
    @RequestMapping(value = "/addHcjg", method = RequestMethod.POST)
    public AjaxResult addHcjg(@RequestBody Map<String, Object> parm) {
        try {
            LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
            List<Map<String, Object>> list = new ArrayList<>();
            String selectList = parm.get("listParams").toString();
            int rest = 0;
            String ywhj = parm.get("ywhj") + "";
            if (!selectList.equals("") && !selectList.equals("null") && selectList != null) {
                JSONObject obj = JSON.parseObject(selectList);
                if (obj != null) {
                    parm.put("username", loginUser.getUsername());
                    // parm.put("xzqdm", obj.get("xzqdm"));
                    // parm.put("pdlx",obj.get("pdlx"));
                    parm.put("pch", obj.get("pch"));

                    //parm.put("xzqdm", obj.get("xzqdm"));
                    parm.put("shr", loginUser.getSysUser().getNickName());
                    parm.put("sfhc", "是");

                    parm.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
                    String strPdlx = parm.get("pdlx") + "";
                    if (strPdlx.equals("合法")) {
                        parm.put("jl_jlpf", parm.get("hf_jlJlpf"));
                    } else if (strPdlx.equals("违法")) {
                        parm.put("jl_jlpf", parm.get("wf_jlJlpf"));
                    } else if (strPdlx.equals("其他")) {
                        parm.put("jl_jlpf", parm.get("qt_jlJlpf"));
                    }

                    String state = parm.get("state") + "";
                    Map<String, Object> item = commonService.queryHcJgById(parm);
                    if (item != null) {
                        commonService.deleteHcJg(parm);
                        commonService.deleteHcjg_hf_dtPwwj(parm);
                        commonService.deleteHcjg_wf_wfpzwh(parm);
                        commonService.deleteHcjg_wf_wftgzmwj(parm);
                        commonService.deleteHcjg_qt_qtpzwh(parm);
                        commonService.deleteHcjg_qt_qtsftgxxydss(parm);
                        commonService.deleteHcjg_qt_qtsfzygd(parm);
                    }
                    rest = commonService.addHcjg(parm);

                    String domains = parm.get("domains") + "";
                    if (!domains.equals("[]") && !domains.equals("null") && domains != "null") {
                        JSONArray arraylist = JSONObject.parseArray(domains);

                        for (int i = 0; i < arraylist.size(); i++) { //遍历输出
                            JSONObject jsonObject = arraylist.getJSONObject(i);
                            String domainType = jsonObject.getString("domainType");
                            if (strPdlx.equals("合法")) {
                                ModelMap map = new ModelMap();
                                map.put("tbbh", parm.get("tbbh"));
                                map.put("xzqdm", parm.get("xzqdm"));
                                map.put("pch", parm.get("pch"));
                                map.put("sort", jsonObject.getString("key"));
                                map.put("hf_zlpwlx1", jsonObject.getString("hfZlpwlx1"));
                                map.put("hf_pzwh", jsonObject.getString("hfPzwh"));
                                map.put("hf_pzxmmc", jsonObject.getString("hfPzxmmc"));
                                map.put("hf_pzzygdmj", jsonObject.getString("hfPzzygdmj"));
                                map.put("hf_pzzygdmjdw", jsonObject.getString("hfPzzygdmjdw"));
                                map.put("hf_pzsj", jsonObject.getString("hfPzsj"));
                                map.put("hf_zlpwlx2", jsonObject.getString("hfZlpwlx2"));
                                map.put("hf_zlpwclmc", jsonObject.getString("hfZlpwclmc"));
                                map.put("ywhj", parm.get("ywhj"));
                                map.put("status", "");
                                int hf_rest = commonService.addHcjg_hf_DtPwwj(map);
                            } else if (strPdlx.equals("违法")) {
                                if (jsonObject.getString("wfZlpwlx1") != null || jsonObject.getString("wfZlpwlx2") != null) {
                                    ModelMap map = new ModelMap();
                                    map.put("tbbh", parm.get("tbbh"));
                                    map.put("xzqdm", parm.get("xzqdm"));
                                    map.put("pch", parm.get("pch"));
                                    map.put("sort", jsonObject.getString("key"));
                                    map.put("wf_zlpwlx1", jsonObject.getString("wfZlpwlx1"));
                                    map.put("wf_pzwh", jsonObject.getString("wfPzwh"));
                                    map.put("wf_pzxmmc", jsonObject.getString("wfPzxmmc"));
                                    map.put("wf_pzzygdmj", jsonObject.getString("wfPzzygdmj"));
                                    map.put("wf_pzzygdmjdw", jsonObject.getString("wfPzzygdmjdw"));
                                    map.put("wf_pzsj", jsonObject.getString("wfPzsj"));

                                    map.put("wf_zlpwlx2", jsonObject.getString("wfZlpwlx2"));
                                    map.put("wf_zlpwclmc", jsonObject.getString("wfZlpwclmc"));
                                    map.put("ywhj", parm.get("ywhj"));
                                    map.put("status", "");
                                    commonService.addHcjg_wf_wftgzmwj(map);
                                } else {
                                    ModelMap map = new ModelMap();
                                    map.put("tbbh", parm.get("tbbh"));
                                    map.put("xzqdm", parm.get("xzqdm"));
                                    map.put("pch", parm.get("pch"));
                                    map.put("sort", jsonObject.getString("key"));
                                    map.put("wf_pzwh", jsonObject.getString("wfPzwh"));
                                    map.put("wf_pzxmmc", jsonObject.getString("wfPzxmmc"));
                                    map.put("wf_pzsj", jsonObject.getString("wfPzsj"));
                                    map.put("ywhj", parm.get("ywhj"));
                                    map.put("status", "");
                                    commonService.addHcjg_wf_wfpzwh(map);
                                }
                            } else if (strPdlx.equals("其他")) {
                                if (jsonObject.getString("qtPzwh") != null) {
                                    ModelMap qtpzwh_map = new ModelMap();
                                    qtpzwh_map.put("tbbh", parm.get("tbbh"));
                                    qtpzwh_map.put("xzqdm", parm.get("xzqdm"));
                                    qtpzwh_map.put("pch", parm.get("pch"));
                                    qtpzwh_map.put("sort", jsonObject.getString("key"));
                                    qtpzwh_map.put("qt_pzwh", jsonObject.getString("qtPzwh"));
                                    qtpzwh_map.put("qt_pzxmmc", jsonObject.getString("qtPzxmmc"));
                                    qtpzwh_map.put("qt_pzsj", jsonObject.getString("qtPzsj"));
                                    qtpzwh_map.put("ywhj", parm.get("ywhj"));
                                    qtpzwh_map.put("status", "");
                                    rest = commonService.adddHcjg_qt_qtpzwh(qtpzwh_map);
                                } else if (jsonObject.getString("qtTgbawjsj") != null) {
                                    ModelMap qtsfzygd_map = new ModelMap();
                                    qtsfzygd_map.put("tbbh", parm.get("tbbh"));
                                    qtsfzygd_map.put("xzqdm", parm.get("xzqdm"));
                                    qtsfzygd_map.put("pch", parm.get("pch"));
                                    qtsfzygd_map.put("sort", jsonObject.getString("key"));
                                    qtsfzygd_map.put("qt_tgbawjsj", jsonObject.getString("qtTgbawjsj"));
                                    qtsfzygd_map.put("qt_clmc", jsonObject.getString("qtClmc"));
                                    qtsfzygd_map.put("ywhj", parm.get("ywhj"));
                                    qtsfzygd_map.put("status", "");
                                    rest = commonService.addHcjg_qt_qtsfzygd(qtsfzygd_map);
                                } else if (jsonObject.getString("qtSftgxxydssclmc") != null) {
                                    ModelMap qtsftgxxydss_map = new ModelMap();
                                    qtsftgxxydss_map.put("tbbh", parm.get("tbbh"));
                                    qtsftgxxydss_map.put("xzqdm", parm.get("xzqdm"));
                                    qtsftgxxydss_map.put("pch", parm.get("pch"));
                                    qtsftgxxydss_map.put("sort", jsonObject.getString("key"));

                                    qtsftgxxydss_map.put("qt_sftgxxydssclmc", jsonObject.getString("qtSftgxxydssclmc"));
                                    qtsftgxxydss_map.put("qt_sftgxxydsspfsj", jsonObject.getString("qtSftgxxydsspfsj"));
                                    qtsftgxxydss_map.put("ywhj", parm.get("ywhj"));
                                    qtsftgxxydss_map.put("status", "");
                                    rest = commonService.addHcjg_qt_qtsftgxxydss(qtsftgxxydss_map);
                                }
                            }
                        }
                    }

                    ModelMap model = new ModelMap();
                    model.put("username", loginUser.getUsername());
                    model.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
                    model.put("xzqdm", obj.getString("xzqdm"));
                    model.put("pch", parm.get("pch") + "");
                    model.put("sfcf", obj.getString("sfcf"));
                    model.put("pdlx", obj.getString("pdlx"));
                    model.put("hczt", obj.getString("hczt"));
                    model.put("ids", parm.get("ids"));

                    if (ywhj.equals("0") && state.equals("未完成")) {
                        list = wpzfUnitHcTaskService.query_unit_w_task_list(model);
                    } else if (ywhj.equals("0") && state.equals("已完成")) {
                        list = wpzfUnitHcTaskService.query_unit_y_task_list(model);
                    } else if (ywhj.equals("1") && state.equals("未完成")) {
                        model.put("sfhc", obj.get("sfhc"));
                        model.put("sftj", obj.get("sftj"));
                        model.put("keyword", obj.get("keyword"));
                        model.put("pdlx", obj.get("pdlx"));
                        model.put("pdlxEj", obj.get("pdlxEj"));
                        model.put("sftg", obj.get("sftg"));
                        model.put("hcjgsm", obj.get("hcjgsm"));
                        list = wpzfJlHcTaskService.query_jl_w_task_list(model);
                    } else if (ywhj.equals("1") && state.equals("已完成")) {
                        model.put("sfhc", obj.get("sfhc"));
                        model.put("sftj", obj.get("sftj"));
                        model.put("keyword", obj.get("keyword"));
                        model.put("pdlx", obj.get("pdlx"));
                        model.put("pdlxEj", obj.get("pdlxEj"));
                        model.put("sftg", obj.get("sftg"));
                        model.put("hcjgsm", obj.get("hcjgsm"));
                        list = wpzfJlHcTaskService.query_jl_y_task_list(model);
                    } else if (ywhj.equals("2") && state.equals("待确认")) {
                        list = wpzfUnitHcTaskService.get_unit_dqr_static_list(model);
                    } else if (ywhj.equals("2") && state.equals("已确认")) {
                        list = wpzfUnitHcTaskService.get_unit_yqr_static_list(model);
                    } else if (ywhj.equals("3") && state.equals("单位未完成")) {
                        parm.put("sfzg", "是");
                        parm.put("username", loginUser.getUsername());
                        parm.put("realname", loginUser.getSysUser().getNickName());
                        int i = wpzfZgTbTaskServiceImpl.update_unit_zgtb(parm);
                        list = wpzfZgTbTaskServiceImpl.query_unit_user_dzgtb_leftlist(model);
                    } else if (ywhj.equals("3") && state.equals("监理未完成")) {
                        parm.put("sfzg", "是");
                        parm.put("username", loginUser.getUsername());
                        parm.put("realname", loginUser.getSysUser().getNickName());
                        int i = wpzfZgTbTaskServiceImpl.update_unit_zgtb(parm);
                        list = wpzfZgTbTaskServiceImpl.query_jl_user_dzgtb_leftlist(model);
                    }
                }
            }
            //按照业务环节值  获取核查结果说明
            Map<String, Object> tbhcjgsm = commonService.getHcjgsmBytbbh(parm);
            if (tbhcjgsm != null) {
                tbhcjgsm.put("username", loginUser.getUsername());
                tbhcjgsm.put("ywhj", parm.get("ywhj") + "");
                commonService.updateHcjg_hcjgsm(tbhcjgsm);  //更新核查结果说明
            }
            return AjaxResult.success("添加核查结果", list, rest);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("填写内容有误", null);
        }
    }

    /*获取上一个图斑*/
    @RequestMapping(value = "/get_last_tbbh", method = RequestMethod.POST)
    public AjaxResult get_last_tbbh(@RequestBody Map<String, Object> parm) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parm.put("username", loginUser.getUsername());
        String ywhj = parm.get("ywhj") + "";
        String state = parm.get("state") + "";
        List<Map<String, Object>> list = new ArrayList<>();
        String selectList = parm.get("listParams").toString();
        if (!selectList.equals("") && !selectList.equals("null") && selectList != null) {
            ModelMap model = new ModelMap();

            JSONObject obj = JSON.parseObject(selectList);
            if (obj != null) {
                model.put("username", loginUser.getUsername());
                try {
                    model.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
                } catch (Exception ex) {

                }
                model.put("xzqdm", obj.getString("xzqdm"));
                model.put("pch", parm.get("pch") + "");
                model.put("sfcf", obj.getString("sfcf"));
                model.put("pdlx", obj.getString("pdlx"));
                model.put("hczt", obj.getString("hczt"));
                model.put("ids", parm.get("ids"));

                if (ywhj.equals("0") && state.equals("未完成")) {
                    list = wpzfUnitHcTaskService.query_unit_w_task_list(model);
                } else if (ywhj.equals("0") && state.equals("已完成")) {
                    list = wpzfUnitHcTaskService.query_unit_y_task_list(model);
                } else if (ywhj.equals("1") && state.equals("未完成")) {
                    model.put("sfhc", obj.get("sfhc"));
                    model.put("sftj", obj.get("sftj"));
                    model.put("keyword", obj.get("keyword"));
                    model.put("pdlx", obj.get("pdlx"));
                    model.put("pdlxEj", obj.get("pdlxEj"));
                    model.put("sftg", obj.get("sftg"));
                    model.put("hcjgsm", obj.get("hcjgsm"));
                    list = wpzfJlHcTaskService.query_jl_w_task_list(model);
                } else if (ywhj.equals("1") && state.equals("已完成")) {
                    model.put("sfhc", obj.get("sfhc"));
                    model.put("sftj", obj.get("sftj"));
                    model.put("keyword", obj.get("keyword"));
                    model.put("pdlx", obj.get("pdlx"));
                    model.put("pdlxEj", obj.get("pdlxEj"));
                    model.put("sftg", obj.get("sftg"));
                    model.put("hcjgsm", obj.get("hcjgsm"));
                    list = wpzfJlHcTaskService.query_jl_y_task_list(model);
                } else if (ywhj.equals("2") && state.equals("待确认")) {
                    list = wpzfUnitHcTaskService.get_unit_dqr_static_list(model);
                } else if (ywhj.equals("2") && state.equals("已确认")) {
                    list = wpzfUnitHcTaskService.get_unit_yqr_static_list(model);
                } else if (state.equals("审核")) {
                    parm.put("sh_submit", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
                    wpzfShTbService.updateShState(parm);
                    model.put("sheng", obj.get("sheng"));
                    model.put("xzqdm", obj.get("xzqdm"));
                    model.put("pch", obj.get("pch"));
                    model.put("pdlx", obj.get("pdlx"));
                    model.put("sfcf", obj.get("sfcf"));
                    model.put("tbbh", obj.get("tbbh"));
                    model.put("sfck", obj.get("sfck"));
                    model.put("sftg", obj.get("sftg"));
                    model.put("hcjgsm", obj.get("hcjgsm"));
                    model.put("px", obj.get("px"));
                    list = wpzfShTbService.query_sh_task_list(model); //查找下一个
                } else if (state.equals("图斑审查")) {
                    list = wpzfJlHcTaskService.query_tbsc_task_list(model);
                } else if (ywhj.equals("3") && state.equals("单位未完成")) {
                    list = wpzfZgTbTaskServiceImpl.query_unit_user_dzgtb_leftlist(model);
                } else if (ywhj.equals("3") && state.equals("单位已完成")) {
                    list = wpzfZgTbTaskServiceImpl.query_unit_user_yzgtb_leftlist(model);
                } else if (ywhj.equals("3") && state.equals("监理未完成")) {
                    list = wpzfZgTbTaskServiceImpl.query_jl_user_dzgtb_leftlist(model);
                } else if (ywhj.equals("3") && state.equals("监理已完成")) {
                    list = wpzfZgTbTaskServiceImpl.query_jl_user_yzgtb_leftlist(model);
                } else if (state.equals("单位负责人图斑管理")) {
                    list = wpzfUnitHcTaskService.dwUnitLeaderLeftList(model);
                } else if (state.equals("未填报")) {
                    model.put("iscl", state);
                    model.put("xxzqdm", obj.getString("xxzqdm"));
                    model.put("jcmjType", obj.getString("jcmjType"));
                    model.put("jcmjValue", obj.getDouble("jcmjValue"));
                    model.put("jcmjRange", obj.get("jcmjRange"));
                    model.put("tbdkmjType", obj.getString("tbdkmjType"));
                    model.put("tbdkmjValue", obj.getDouble("tbdkmjValue"));
                    model.put("tbdkmjRange", obj.get("tbdkmjRange"));
                    model.put("tbdkqzgdmjType", obj.getString("tbdkqzgdmjType"));
                    model.put("tbdkqzgdmjValue", obj.getDouble("tbdkqzgdmjValue"));
                    model.put("tbdkqzgdmjRange", obj.get("tbdkqzgdmjRange"));
                    model.put("tbdkqzjbntmjType", obj.getString("tbdkqzjbntmjType"));
                    model.put("tbdkqzjbntmjValue", obj.getDouble("tbdkqzjbntmjValue"));
                    model.put("tbdkqzjbntmjRange", obj.get("tbdkqzjbntmjRange"));
                    model.put("tbnydmjType", obj.getString("tbnydmjType"));
                    model.put("tbnydmjValue", obj.getDouble("tbnydmjValue"));
                    model.put("tbnydmjRange", obj.get("tbnydmjRange"));
                    model.put("tbdkstmjType", obj.getString("tbdkstmjType"));
                    model.put("tbdkstmjValue", obj.getDouble("tbdkstmjValue"));
                    model.put("tbdkstmjRange", obj.get("tbdkstmjRange"));
                    model.put("tbdkstbhhxmjType", obj.getString("tbdkstbhhxmjType"));
                    model.put("tbdkstbhhxmjValue", obj.getDouble("tbdkstbhhxmjValue"));
                    model.put("tbdkstbhhxmjRange", obj.get("tbdkstbhhxmjRange"));
                    list = xjtbTbBaseService.querytbxxByjcbhidx(model);
                } else if (state.equals("已填报")) {
                    model.put("iscl", state);
                    model.put("xxzqdm", obj.getString("xxzqdm"));
                    model.put("jcmjType", obj.getString("jcmjType"));
                    model.put("jcmjValue", obj.getDouble("jcmjValue"));
                    model.put("jcmjRange", obj.get("jcmjRange"));
                    model.put("tbdkmjType", obj.getString("tbdkmjType"));
                    model.put("tbdkmjValue", obj.getDouble("tbdkmjValue"));
                    model.put("tbdkmjRange", obj.get("tbdkmjRange"));
                    model.put("tbdkqzgdmjType", obj.getString("tbdkqzgdmjType"));
                    model.put("tbdkqzgdmjValue", obj.getDouble("tbdkqzgdmjValue"));
                    model.put("tbdkqzgdmjRange", obj.get("tbdkqzgdmjRange"));
                    model.put("tbdkqzjbntmjType", obj.getString("tbdkqzjbntmjType"));
                    model.put("tbdkqzjbntmjValue", obj.getDouble("tbdkqzjbntmjValue"));
                    model.put("tbdkqzjbntmjRange", obj.get("tbdkqzjbntmjRange"));
                    model.put("tbnydmjType", obj.getString("tbnydmjType"));
                    model.put("tbnydmjValue", obj.getDouble("tbnydmjValue"));
                    model.put("tbnydmjRange", obj.get("tbnydmjRange"));
                    model.put("tbdkstmjType", obj.getString("tbdkstmjType"));
                    model.put("tbdkstmjValue", obj.getDouble("tbdkstmjValue"));
                    model.put("tbdkstmjRange", obj.get("tbdkstmjRange"));
                    model.put("tbdkstbhhxmjType", obj.getString("tbdkstbhhxmjType"));
                    model.put("tbdkstbhhxmjValue", obj.getDouble("tbdkstbhhxmjValue"));
                    model.put("tbdkstbhhxmjRange", obj.get("tbdkstbhhxmjRange"));
                    list = xjtbTbBaseService.querytbxxByjcbhidx(model);
                } else if (state.equals("全部")) {
                    model.put("xxzqdm", obj.getString("xxzqdm"));
                    model.put("jcmjType", obj.getString("jcmjType"));
                    model.put("jcmjValue", obj.getDouble("jcmjValue"));
                    model.put("jcmjRange", obj.get("jcmjRange"));
                    model.put("tbdkmjType", obj.getString("tbdkmjType"));
                    model.put("tbdkmjValue", obj.getDouble("tbdkmjValue"));
                    model.put("tbdkmjRange", obj.get("tbdkmjRange"));
                    model.put("tbdkqzgdmjType", obj.getString("tbdkqzgdmjType"));
                    model.put("tbdkqzgdmjValue", obj.getDouble("tbdkqzgdmjValue"));
                    model.put("tbdkqzgdmjRange", obj.get("tbdkqzgdmjRange"));
                    model.put("tbdkqzjbntmjType", obj.getString("tbdkqzjbntmjType"));
                    model.put("tbdkqzjbntmjValue", obj.getDouble("tbdkqzjbntmjValue"));
                    model.put("tbdkqzjbntmjRange", obj.get("tbdkqzjbntmjRange"));
                    model.put("tbnydmjType", obj.getString("tbnydmjType"));
                    model.put("tbnydmjValue", obj.getDouble("tbnydmjValue"));
                    model.put("tbnydmjRange", obj.get("tbnydmjRange"));
                    model.put("tbdkstmjType", obj.getString("tbdkstmjType"));
                    model.put("tbdkstmjValue", obj.getDouble("tbdkstmjValue"));
                    model.put("tbdkstmjRange", obj.get("tbdkstmjRange"));
                    model.put("tbdkstbhhxmjType", obj.getString("tbdkstbhhxmjType"));
                    model.put("tbdkstbhhxmjValue", obj.getDouble("tbdkstbhhxmjValue"));
                    model.put("tbdkstbhhxmjRange", obj.get("tbdkstbhhxmjRange"));
                    list = xjtbTbBaseService.querytbxxByjcbhidx(model);
                } else if (state.equals("年度核查未填报")) {
                    model.put("year", parm.get("year"));
                    list = wpzfNdhcXjtbTbBaseService.querytbxxByjcbhidx(model);
                }

            }
        }
        return AjaxResult.success("获取图斑编号", list);
    }


    @RequestMapping(value = "/export", method = RequestMethod.POST)
    public AjaxResult export(@RequestBody Map<String, Object> parm, HttpServletResponse response) {
        List<WpCJ_TB_Hcjg_2023DTO> item = new ArrayList<>();
        ExcelUtils excel = new ExcelUtils();
        String rest = "";
        String msg = "";
        String category = parm.get("category") + "";
        String sheetName = "";
        //String xzqdm=parm.get("xzqdm")+"";
        String xzqdm = "130125";
        try {
//      parm.put("xzqdm", xzqdm);
//      parm.put("pch", "9月");
//      parm.put("username", "19102868279");
//      parm.put("dwmc", "四川国地信息技术有限公司");
//      parm.put("ywhj", "0");

            WpCJ_TB_Hcjg_2023DTO tbhcjg = new WpCJ_TB_Hcjg_2023DTO();

            List<Map<String, Object>> ColNamelist = commonService.queryHcJgByColumnName();   //获取核查结果的所有列明
            List<WpCjTbhcjg2023DTO> list = commonService.getTbhcjglist(parm);  //核查结果
            tbhcjg.setWpCjTbhcjg2023DTOS(list);
            tbhcjg.setwpCjTbhcjg2023DTOS_ColumnNameList(ColNamelist);
            item.add(tbhcjg);


            List<WpCjTbhcjgHftgzmwj2023DTO> hftgzmwjList = wpzfTbhcjgService.getHftgzmwj(parm);  //核查结果 合法*******动态批文
            if (hftgzmwjList.size() > 0) {
                List<Map<String, Object>> HftgzmwjByColumnName = commonService.queryHftgzmwjByColumnName();  //合法*******动态批文 列名

                tbhcjg.setWpCjTbhcjgHftgzmwj2023DTO(hftgzmwjList);
                tbhcjg.setwpCjTbhcjgHftgzmwj2023DTO_ColumnNameList(HftgzmwjByColumnName);
                item.add(tbhcjg);
            }


            List<WpCjTbhcjgWftgzmwj2023DTO> WftgzmwjList = wpzfTbhcjgService.getWftgzmwj(parm);  //核查结果 违法*******违法提供证明文件
            if (WftgzmwjList.size() > 0) {
                List<Map<String, Object>> WftgzmwjByColumnName = commonService.queryWfpzwhByColumnName();  //列名

                tbhcjg.setWpCjTbhcjgWftgzmwj2023DTO(WftgzmwjList);
                tbhcjg.setwpCjTbhcjgHftgzmwj2023DTO_ColumnNameList(WftgzmwjByColumnName);
                item.add(tbhcjg);

            }
            List<WpCjTbhcjgWfpzwh2023DTO> WfpzwhList = wpzfTbhcjgService.getWfpzwh(parm);  //核查结果 违法*******批准文号
            if (WfpzwhList.size() > 0) {
                List<Map<String, Object>> WfpzwhByColumnName = commonService.queryWftgzmwjByColumnName();  //列名

                tbhcjg.setWpCjTbhcjgWfpzwh2023DTO(WfpzwhList);
                tbhcjg.setwpCjTbhcjgWfpzwh2023DTO_ColumnNameList(WfpzwhByColumnName);
                item.add(tbhcjg);
            }


            List<WpCjTbhcjgQtpzwh2023DTO> QtpzwhList = wpzfTbhcjgService.getQtpzwh(parm);  //核查结果  其他*******批准文号
            if (QtpzwhList.size() > 0) {
                List<Map<String, Object>> QtpzwhByColumnName = commonService.queryQtpzwhByColumnName();  //列名

                tbhcjg.setWpCjTbhcjgQtpzwh2023DTO(QtpzwhList);
                tbhcjg.setwpCjTbhcjgQtpzwh2023DTO_ColumnNameList(QtpzwhByColumnName);
                item.add(tbhcjg);
            }
            List<WpCjTbhcjgQtsfzygd2023DTO> QtsfzygdList = wpzfTbhcjgService.getQtsfzygd(parm);  //核查结果 其他*******是否占用耕地
            if (QtsfzygdList.size() > 0) {
                List<Map<String, Object>> QtsfzygdByColumnName = commonService.queryQtsfzygdByColumnName();  //列名

                tbhcjg.setWpCjTbhcjgQtsfzygd2023DTO(QtsfzygdList);
                tbhcjg.setwpCjTbhcjgQtsfzygd2023DTO_ColumnNameList(QtsfzygdByColumnName);
                item.add(tbhcjg);
            }
            List<WpCjTbhcjgQtsftgxxydss2023DTO> QtsftgxxydssList = wpzfTbhcjgService.getQtsftgxxydss(parm);  //核查结果-是否提供先行用地手续
            if (QtsftgxxydssList.size() > 0) {
                List<Map<String, Object>> QtsftgxxydssByColumnName = commonService.queryQtsftgxxydssByColumnName();  //列名

                tbhcjg.setWpCjTbhcjgQtsftgxxydss2023DTO(QtsftgxxydssList);
                tbhcjg.setwpCjTbhcjgQtsftgxxydss2023DTO_ColumnNameList(QtsftgxxydssByColumnName);
                item.add(tbhcjg);
            }
            rest = excel.export(response, category, item, xzqdm, parm);
            if (rest.equals("success")) {
                msg = "导出成功";
            } else {
                msg = "导出失败";
            }
            return AjaxResult.success(msg, rest);
        } catch (Exception e) {
            e.printStackTrace();
            msg = "导出失败";
        }
        return AjaxResult.error(msg, -1);
    }


    /*根据当前用户获取所有批次*/
    @RequestMapping(value = "/get_user_pchlist", method = RequestMethod.POST)
    public AjaxResult get_user_pchlist(@RequestBody Map<String, Object> parm) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parm.put("username", loginUser.getUsername());
        //获取当前用户所有已完成的任务

        List<Map<String, Object>> rest = commonService.get_user_pchlist(parm);
        if (rest != null) {

            return AjaxResult.success("获取所有批次成功", rest);
        }

        return AjaxResult.error("获取所有批次失败", -1);
    }

    /*根据当前单位所有的人员*/
    @RequestMapping(value = "/get_unit_userlist", method = RequestMethod.POST)
    public AjaxResult get_unit_userlist(@RequestBody Map<String, Object> parm) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parm.put("dwmc", loginUser.getSysUser().getDept().getDeptName());
        //获取当前用户所有已完成的任务

        List<Map<String, Object>> rest = commonService.get_unit_userlist(parm);
        if (rest != null) {

            return AjaxResult.success("获取当前单位所有的人员成功", rest);
        }

        return AjaxResult.error("获取当前单位所有的人员失败", -1);
    }

    //根据当前监理获取所有批次号
    @RequestMapping(value = "/getJlPch", method = RequestMethod.POST)
    public AjaxResult getJlPch(@RequestBody Map<String, Object> parm) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parm.put("username", loginUser.getUsername());
        List<Map<String, Object>> rest = commonService.getJlPch(parm);
        if (rest != null) {
            return AjaxResult.success("根据当前监理获取所有批次号 成功", rest);
        }
        return AjaxResult.error("根据当前监理获取所有批次号 失败", -1);
    }

    //保存pdf导出信息
    @RequestMapping(value = "/savePdfInfo", method = RequestMethod.POST)
    public AjaxResult savePdfInfo(@RequestBody Map<String, Object> parm) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        parm.put("username", loginUser.getUsername());
        Integer rest = commonService.savePdfInfo(parm);
        if (rest > 0) {
            return AjaxResult.success("保存pdf导出信息 成功", rest);
        }
        return AjaxResult.error("保存pdf导出信息 失败", -1);
    }

    //获取pdf导出信息
    @RequestMapping(value = "/getPdfInfo", method = RequestMethod.POST)
    public AjaxResult getPdfInfo(@RequestBody Map<String, Object> parm) {
        List<Map<String, Object>> rest = commonService.getPdfInfo(parm);
        return AjaxResult.success("获取pdf导出信息 成功", rest);
    }

    //获取核查结果说明
    @RequestMapping(value = "/getHcjgsmlx", method = RequestMethod.POST)
    public AjaxResult getHcjgsmlx(@RequestBody Map<String, Object> parm) {
        List<Map<String, Object>> rest = commonService.getHcjgsmlx(parm);
        return AjaxResult.success("获取核查结果说明 成功", rest);
    }

    @Log(title ="获取pdf",businessType = BusinessType.OTHER)
    //获取核查结果说明
    @RequestMapping(value = "/getPDF", method = RequestMethod.POST,produces = {"application/pdf;charset=UTF-8"})
    public void getPDF(@RequestBody Map<String, Object> parm,HttpServletResponse response) {
        try {
            String rest = commonService.getPDF(parm,response);
            String msg="";
            if (rest.contains("error")) {
                msg = "pdf导出失败";
            } else {
                msg = "pdf导出成功";
            }
        } catch (Exception e){
            e.printStackTrace();

        }
    }
}
